package com.wc.AlgoOJ_train.train5_数据结构.c1_线性表.DS0207_光头强的疑问;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congege
 * @Description
 * @Date Created in 2024/2/3-9:55
 * http://43.138.190.70:8888/p/DS0207
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static char[] s;
    static char[] t;
    static int n, m;
    static int[] next = new int[N];
    static int[] nextVal = new int[N];

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        s = sc.next().toCharArray();
        t = sc.next().toCharArray();
        next[0] = -1;
        next[1] = 0;

        for (int i = 2; i <= m; i++) {
            int k = next[i - 1];
            while (k != -1 && t[k] != t[i - 1]) {
                k = next[k];
            }
            next[i] = k + 1;
        }

        nextVal[0] = -1;
        for (int i = 1; i < m; i++) {
            if (t[i] == t[next[i]]) {
                nextVal[i] = nextVal[next[i]];
            } else {
                nextVal[i] = next[i];
            }
        }
        int pos = -1;
        int res = 0;
        while (pos < n) {
            pos = kmp(pos + 1);
            if (pos != -1) {
                res++;
            } else {
                break;
            }
        }
        out.println(res);
        out.flush();
    }

    static int kmp(int pos) {
        if (pos >= n) {
            return -1;
        }
        int i = pos;
        int j = 0;
        while (i < n && j < m) {
            if (j == -1 || s[i] == t[j]) {
                i++;
                j++;
            } else {
                j = nextVal[j];
            }
        }

        if (j >= m) {
            return i - j;
        }
        return -1;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    boolean hasNext() {
        while (st == null || !st.hasMoreElements()) {
            String s = nextLine();
            if (s == null) {
                return false;
            }
            st = new StringTokenizer(s);
        }

        return true;
    }
}
